<template>
  <div>
    <el-row style="margin-bottom:20px;display:flex;justify-content:flex-start">
      <el-input placeholder="设备名称" v-model="searchrepair.ep_ename" style="width:20%;margin-right:10px" clearable></el-input>

      <el-input placeholder="规格型号" v-model="searchrepair.scale" style="width:20%;margin-right:10px" clearable></el-input>
      <el-input placeholder="管理编号" v-model="searchrepair.managenum" style="width:20%;margin-right:10px" clearable></el-input>
      <el-date-picker
        v-model="repairdate"
        clearable
        style="margin-right:15px;width:25%"
        type="daterange"
        rangeSeparator="至"
        startPlaceholder="申请时间"
        endPlaceholder="申请时间"
        valueFormat="yyyy-MM-dd"
      >
      </el-date-picker>
      <el-input placeholder="申请人" v-model="searchrepair.sqrname" style="width:20%;margin-right:10px" clearable></el-input>
      <el-select v-model="searchrepair.repair_type" placeholder="请选择处理方式" style="width:20%;margin-right:10px" clearable>
        <el-option
          v-for="item in repairtypeArr"
          :key="item.value"
          :label="item.hash.code_name"
          :value="item.hash.code_id"
        ></el-option>
      </el-select>

      <el-button size="mini" type="primary" @click="geteqrepairList">搜索</el-button>
    </el-row>
    <el-divider></el-divider>
    <el-row>
      <el-button size="mini" type="primary" @click="doapprove">审批</el-button>
    </el-row>
    <el-dialog title="审核设备维修" :visible.sync="dialogVisible">
      <el-form labelWidth="150px">
        <el-form-item label="审批意见" class="is-required" style="width:100%">
          <el-input
            type="textarea"
            :rows="3"
            v-model="doapprovedata.pz_content"
            placeholder="请输入内容"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="审批日期" class="is-required" style="width:100%">
          <el-date-picker
            type="date"
            style="width:100%"
            v-model="doapprovedata.pztime"
            placeholder="选择审批日期"
            valueFormat="yyyy-MM-dd"
            clearable
          ></el-date-picker>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="dialogVisible = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="submitapprove">确 定</el-button>

      </span>
    </el-dialog>
    <repairList :eqrepairList="eqrepairList" :choosedp.sync="choosedp" :pagobj.sync="pagobj" :ismanager="false" :islast="false"></repairList>
  </div>
</template>

<script>
import repairList from '~/components/apparatus/eqrepair/repairList.vue';
import neweqrepair from '~/components/apparatus/eqrepair/neweqrepair.vue';

export default {
  components: {
    repairList,
    neweqrepair,
  },
  data() {
    return {
      dialogVisible: false,
      ts: this.newStore(),
      searchrepair: {},
      isedit: false,
      repairdate: ['', ''],
      eqrepairList: [],
      choosedp: [],
      editdata: {},
      repairtypeArr: [],
      doapprovedata: {

      },
      statusArr: [{
        label: '待审核',
        value: '0',
      }, {
        label: '审核通过',
        value: '1',
      }, {
        label: '已填写处理记录',
        value: '3',
      }],
      isneweqrepair: false,
      pagobj: {
        currentPage3: 1,
        pagesize: 10,
        total: 10,
      },
    };
  },
  created() {
    this.getcodeData('0404', '04', 'repairtypeArr');
    this.geteqrepairList();
  },
  methods: {
    doapprove() {
      if (this.choosedp.length == 0) {
        this.$message({
          type: 'info',
          message: '请先勾选维修记录',
        });
        return;
      }

      this.dialogVisible = true;
    },
    submitapprove() {
      const deletearr = [];
      for (let i = 0; i < this.choosedp.length; i += 1) {
        deletearr.push(this.choosedp[i].hash.rid);
      }
      this.$confirm('确认审批已选择的维修记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          const req = {
            handle:
              'DD5D108B99FC12B78456C40D977EBA89DCCC094D1456DACEA5A0DC9709260BE0AAD3A303B45EC63D',
            rid: deletearr,
            pzrid: localStorage.getItem('pid'),
          };
          this.spost(this.ts, '/mainservlet', req).then(() => {
            this.$message({
              type: 'success',
              message: '审批提交成功',
            });
            this.geteqrepairList();
            this.dialogVisible = false;
          });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消',
          });
        });
    },
    // 公共方法获取代码项
    getcodeData(supid, codetype, arrname) {
      const req = {
        handle: '67A5B6FEF17D97DECF116BDF95B95C0B167942DD3F1604F9',
        supid,
        codetype,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this[arrname] = ts.d.data.operation1;
      });
    },

    geteqrepairList() {
      if (this.repairdate == null) {
        this.repairdate = [];
      }
      const req = this.searchrepair;
      req.status = '0';
      req.handle = 'DD5D108B99FC12B78456C40D977EBA89DCCC094D1456DACED880EEABFCB4D9F1627154A1FBB7F4B9';
      [req.sqtime_begin] = [this.repairdate[0]];
      [req.sqtime_end] = [this.repairdate[1]];
      req.start = (this.pagobj.currentPage3 - 1) * this.pagobj.pagesize;
      req.limit = this.pagobj.pagesize;
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.eqrepairList = ts.d.data.operation1;
        this.pagobj.total = parseInt(ts.d.data.operation2[0].hash.allrs);
      });
    },
  },
};
</script>
<style >

</style>

